<template>
	<view class="main">

		<view class="logo-box">
			<!-- <image class="logo" src="/static/img/loginlog.png"></image> -->
		</view>

		<view class="content">
			<wInput type="text" maxlength="11" placeholder="请输入用户名" v-model="username"></wInput>
			<wInput class="textInput" type="password" placeholder="请输入密码" v-model="password"></wInput>

			<wButton class="btn-login" text="登 录" bgColor="rgba(0,0,0,0.8)" :rotate="isRotate"
				@click.native="startLogin()"></wButton>
		</view>

		<view class="foot"></view>

		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import wInput from '@/components/watch-login/watch-input.vue'
	import wButton from '@/components/watch-login/watch-button.vue'
	let encMe = require('@/utils/js/DesMD5.js').encMe;
	let uuid = require('@/utils/js/DesMD5.js').uuid;

	export default {
		components: {
			wInput,
			wButton
		},
		data() {
			return {
				username: "admin",
				password: "123456",
				isRotate: false,
			}
		},
		onLoad(option) {

		},
		methods: {
			startLogin() {

				if (this.isRotate) {
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.username == "") {
					this.$gl.toastWarning('请输入用户名');
					return;
				}

				const userid = this.username;
				const p = this.password;
				const Model = {};
				const key = uuid(8, 16);

				Model["UserCode"] = encMe(this.username, key);
				Model["W"] = encMe(p, key);
				Model["key"] = key;
				Model["Code"] = "123456";

				this.isRotate = true;
				setTimeout(() => {
					this.isRotate = false
				}, 2000)


				this.$gl.toastSuccess("登录成功").then(res => {
					uni.setStorageSync('token', "token");
					uni.setStorageSync('refreshtoken', "refreshtoken")
					uni.redirectTo({
						url: "/pages/home"
					})
				})

				// this.$api.myAjaxFunc("/api/Login/CheckLogin", Model, {
				// 	loading: false
				// }).then((res) => {
				// 	if (res.Success) {

				// 		uni.setStorageSync('token', res.Token);
				// 		uni.setStorageSync('refreshtoken', res.RefreshToken);

				// 		this.$gl.toastSuccess("登录成功").then(res => {
				// 			uni.redirectTo({
				// 				url: "/pages/home"
				// 			})
				// 		})

				// 	} else {

				// 		this.$gl.toastFail('登录失败' + res.Message)
				// 		this.isRotate = false
				// 	}
				// })

			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		height: 100vh;
		background-image: url('~@/static/img/login.jpg');
		background-size: 100% 100%;
		opacity: 0.9;
		z-index: -1;
	}

	.logo-box {
		text-align: center;
		padding: 100px 0px 0px 0px;

		.logo {
			height: 100px;
			width: 100px;
		}
	}

	.content {
		padding: 40px;

		.btn-login {
			margin-top: 30px;
		}
	}

	.foot {
		height: 30vh;
		display: flex;
		justify-content: center;
		align-items: flex-end;
		color: #FFFFFF;
	}
</style>
